#ifndef _RIGID_BODY_H_
#define _RIGID_BODY_H_

#include "Polygon.h"
#include "SDM.h"
#include <string>

using namespace std;

class RigidBody
{
public:
	RigidBody(void);
	~RigidBody(void);
	RigidBody(string filename, double density, double res);

	void initRigidBody(initializeFunc setUp);

	void computeMassProperty();
	void computeCenterOfMass();
	void computeMomentOfInertia();

	void rebuildMatrices();

	Vec2d getWorldVelocity(Vec2d x);
	Vec2d getPointWorldToBody(Vec2d p);
	Vec2d getPointBodyToWorld(Vec2d p);
	Vec2d getVectorWorldToBody(Vec2d v);
	Vec2d getVectorBodyToWorld(Vec2d v);
	
	Value evaluateSDM(Vec2d p, bool compute_normal);

	void updatePos(double dt);
	void updateVel(double dt);
	void applyForce(Vec2d x, Vec2d f);

	void resetForce();

	Polygon* poly;
	SDM* sdm;

	Vec2d netForce;
	double netTorque;

	Vec2d pos;
	double orientation;

	Vec2d vel;
	double rotation;

	Mat22d orientationMatrix;
	Mat22d inverseOrientationMatrix;

	Vec2d cm;
	double moment;
	double density;
	double res;
	double mass;

	double radius;
};

typedef vector<RigidBody*> RigidBodyList;

#endif



